import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;


public class P52 {
	private static void permutation(List<String> list, String text, String result, int length) {
		
		if (result.length() > length) {
			return;
		}
		
		if (result.length() == length) {			
			list.add(result);
			return;
		}
		
		for (int i = 0; i < text.length(); i++) {
			permutation(list, text.substring(0, i) + text.substring(i + 1), result + text.charAt(i), length);
		}		
	}
	
	private static void permutation(List<String> list, String text, String result) {
		if (text.length() == 0) {
			list.add(result);
			return;
		}
		
		for (int i = 0; i < text.length(); i++) {
			permutation(list, text.substring(0, i) + text.substring(i + 1), result + text.charAt(i));
		}		
	}
	
	private static List<String> permutation(String text) {
		List<String> list = new ArrayList<String>();
		permutation(list, text, "");
		return new ArrayList<String>(new HashSet<String>(list));
	}
	
	private static List<String> permutation(String text, int length) {
		List<String> list = new ArrayList<String>();
		permutation(list, text, "", length);
		return new ArrayList<String>(new HashSet<String>(list));
	}
	
	public static void main(String[] args) {
//		List<String> list = permutation("0123", 2);
//		for (String text : list) {
//			System.out.println(text);
//		}

		for (int position = 2; true; position++) {
			List<String> list = permutation("0123456789", position);
			
			
			for (String num : list) {
				
				Set<String> set = new HashSet<String>(permutation(num));
				
				boolean isOK = true;
				for (int x = 2; x <= 6; x++) {
					if (!set.contains(String.valueOf(Integer.parseInt(num) * x))) {
						isOK = false;
						break;
					}
				}
				
				if(isOK) {
					System.out.println(">>>" + num);
					System.out.println(set);
					return;
				}
			}
			
		}	
	}
	
}
